# -*- coding: utf-8 -*-
import scrapy
from scrapy.http.response.html import HtmlResponse

class QiushiSpider(scrapy.Spider):
    name = 'qiushi'
    allowed_domains = ['www.qiushibaike.com']
    start_urls = ['https://www.qiushibaike.com/text/page/1/']
    basic='https://www.qiushibaike.com'

    def parse(self, response):
        html=response.xpath('//div[@id="content-left"]')[0]
        lis=html.xpath('./div[contains(@class,"article block untagged mb15")]')
        for li in lis:
            auth=li.xpath('./div[@class="author clearfix"]//h2/text()')[0].get().strip()
            article=li.xpath('.//span[1]/text()')[0].get().strip()
            duanzi={'auth':auth,'article':article}
            print(duanzi)
            yield duanzi
        href=html.xpath('//ul[@class="pagination"]/li[last()]/a/@href').get()
        print(href)
        print('*'*30)
        if not href:
            return
        else:
            yield scrapy.Request(self.basic+href,callback=self.parse)


